#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }

    if (n == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    // 预处理left数组：left[i]表示以i结尾的最长连续复读段长度
    vector<int> left(n, 1);
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == s[i - 1])
        {
            left[i] = left[i - 1] + 1;
        }
        else
        {
            left[i] = 1;
        }
    }

    // 预处理right数组：right[i]表示以i开头的最长连续复读段长度
    vector<int> right(n, 1);
    for (int i = n - 2; i >= 0; --i)
    {
        if (s[i] == s[i + 1])
        {
            right[i] = right[i + 1] + 1;
        }
        else
        {
            right[i] = 1;
        }
    }

    // 初始最大值：不删除任何消息时的最长复读段
    int max_o = *max_element(left.begin(), left.end());
    int after_delete = max_o;

    // 尝试删除每个可能的消息（i），检查能否合并前后复读段
    for (int i = 1; i < n - 1; ++i)
    {
        int prev = i - 1;
        int next = i + 1;
        if (s[prev] == s[next])
        {
            // 合并前缀和后缀的复读段长度
            int date = left[prev] + right[next];
            if (date > after_delete)
            {
                after_delete = date;
            }
        }
    }

    cout << after_delete << endl;
    return 0;
}